package dcc.service;

import java.util.List;

import dcc.model.Dictionary;
import dcc.model.DictionaryItem;
import dcc.persistence.DictionaryMapper;

public class DictionaryService extends BaseService {

	private DictionaryMapper dictionaryMapper;

	public void setDictionaryMapper(DictionaryMapper dictionaryMapper) {
		this.dictionaryMapper = dictionaryMapper;
	}

	public DictionaryService() {
		super(DictionaryService.class);
	}

	public List<Dictionary> getAllKey() {
		return dictionaryMapper.selectAllKey();
	}

	public List<DictionaryItem> getAllValuesByKey(int key) {
		return dictionaryMapper.selectValuesByKey(key);
	}

	public void saveItem(DictionaryItem item) {
		if (item.getId() != 0) {
			dictionaryMapper.updateItem(item);
		} else {
			dictionaryMapper.insertItem(item);
		}
	}

	public void removeItem(int id) {
		this.dictionaryMapper.deleteById(id);
	}

	public Dictionary getByKey(String key) {
		return dictionaryMapper.selectByKey(key);
	}

}
